package com.spica.platform.base.exception.errorcode;

import com.spica.platform.common.utils.StringUtil;

import java.util.Arrays;

/**
 * 返回码定义-定义通用的返回码枚举值
 * 整个系统通用编码 xx_xx_xxxx (服务标识_业务_错误编号，便于错误快速定位
 */
public enum RtnCodeEnum implements IErrorCode {
	SUCCESS("0", "操作成功"),
	FAIL("1", "操作失败"),
	NOT_FOUND_ERROR("10001", "未查询到信息"),
	SAVE_ERROR("10002", "保存信息失败"),
	UPDATE_ERROR("10003", "更新信息失败"),
	VALIDATE_ERROR("10004", "数据检验失败"),
	SYSTEM_ERROR("10007", "系统异常"),
	BUSINESS_ERROR("10008", "业务异常"),
	TRANSFER_STATUS_ERROR("10010", "当前状态不正确，请勿重复提交"),
	UN_KNOWN_ERROR("00000", "未知系统异常");

	private String rtnCod;
	private String rtnMsg;

	RtnCodeEnum(String rtnCod, String rtnMsg) {
		this.rtnCod = rtnCod;
		this.rtnMsg = rtnMsg;
	}

	public String getRtnCod() {
		return rtnCod;
	}

	@Override
	public String getRtnMessage() {
		return rtnMsg;
	}

	@Override
	public String getRtnCode() {
		return rtnCod;
	}

	@Override
	public IErrorCode getInstanceByErrorCode(String rtnCod) {
		return Arrays.stream(RtnCodeEnum.values())
				.filter(rtnCodeEnum -> StringUtil.equals(rtnCodeEnum.rtnCod, rtnCod))
				.findFirst().orElse(RtnCodeEnum.UN_KNOWN_ERROR);
	}
}
